package com.tianyu.inspection.controller;

import com.tianyu.inspection.common.Constants;
import com.tianyu.inspection.common.annotation.Permission;
import com.tianyu.inspection.entity.model.QueryMo;
import com.tianyu.inspection.entity.vo.Ro;
import com.tianyu.inspection.service.api.IProjectStatisticsService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**********************************
 * @Author YSW
 * @Description 统计相关接口
 * @Date 2021/2/24 - 10:54
 **********************************/

@RestController
@RequestMapping("/api/2.0/statistics")
public class ProjectStatisticsController {

    @Resource
    private IProjectStatisticsService projectStatisticsService;

    @GetMapping(value = "/projectSummary")
    @Permission(value = 2, tags = Constants.API_COMPANY)
    public Ro<Object> projectSummaryStatistics(@RequestHeader("u-projectId") Integer projectId) {
        return new Ro<>().setContent(projectStatisticsService.projectSummaryStatistics(projectId));
    }

    @GetMapping(value = "/flyTask")
    @Permission(value = 2, tags = Constants.API_COMPANY)
    public Ro<Object> flyTaskStatistics(@RequestHeader("u-projectId") Integer projectId, HttpServletRequest request) {
        QueryMo queryMo = QueryMo.getQueryMo(request);
        Integer type = queryMo.getInteger("type");
        String startTime = queryMo.getString("startTime");
        String endTime = queryMo.getString("endTime");
        return new Ro<>().setContent(projectStatisticsService.flyTaskStatistics(projectId, type, startTime, endTime));
    }

    @GetMapping(value = "/pipeline")
    @Permission(value = 2, tags = Constants.API_COMPANY)
    public Ro<Object> pipelineStatistics(@RequestHeader("u-projectId") Integer projectId, HttpServletRequest request) {
        QueryMo queryMo = QueryMo.getQueryMo(request);
        Integer type = queryMo.getInteger("type");
        String startTime = queryMo.getString("startTime");
        String endTime = queryMo.getString("endTime");
        return new Ro<>().setContent(projectStatisticsService.pipelineStatistics(projectId, type, startTime, endTime));
    }

    @GetMapping(value = "/orthographic")
    @Permission(value = 2, tags = Constants.API_COMPANY)
    public Ro<Object> orthographicStatistics(@RequestHeader("u-projectId") Integer projectId, HttpServletRequest request) {
        QueryMo queryMo = QueryMo.getQueryMo(request);
        Integer type = queryMo.getInteger("type");
        String startTime = queryMo.getString("startTime");
        String endTime = queryMo.getString("endTime");
        return new Ro<>().setContent(projectStatisticsService.orthographicImageStatistics(projectId, type, startTime, endTime));
    }


    @GetMapping(value = "/danger")
    @Permission(value = 2, tags = Constants.API_COMPANY)
    public Ro<Object> dangerStatistics(@RequestHeader("u-projectId") Integer projectId, HttpServletRequest request) {
        QueryMo queryMo = QueryMo.getQueryMo(request);
        Integer type = queryMo.getInteger("type");
        String startTime = queryMo.getString("startTime");
        String endTime = queryMo.getString("endTime");
        return new Ro<>().setContent(projectStatisticsService.dangerStatistics(projectId, type, startTime, endTime));
    }


    @GetMapping(value = "/danger/details")
    @Permission(value = 2, tags = Constants.API_COMPANY)
    public Ro<Object> dangerDetailsStatistics(@RequestHeader("u-projectId") Integer projectId, HttpServletRequest request) {
        QueryMo queryMo = QueryMo.getQueryMo(request);
        Integer type = queryMo.getInteger("type");
        String startTime = queryMo.getString("startTime");
        String endTime = queryMo.getString("endTime");
        return new Ro<>().setContent(projectStatisticsService.dangerDerailsStatistics(projectId, type, startTime, endTime));
    }

    @GetMapping(value = "/infrastructure")
    @Permission(value = 2, tags = Constants.API_COMPANY)
    public Ro<Object> infrastructureStatistics(@RequestHeader("u-projectId") Integer projectId) {
        return new Ro<>().setContent(projectStatisticsService.infrastructureStatistics(projectId));
    }
}
